package com.example.instagram.controller;

import com.example.instagram.service.ActionService;
import com.example.instagram.vo.CodeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author: dangwen
 * @createDate: 2021/3/8
 */
@RestController
public class ActionController {

    @Autowired
    private ActionService actionService;

    @GetMapping("ins/testRun")
    public void run(){
        System.out.println("1");
    }

    /**
     * 第一步：获取授权：144209597573899
     */
    @GetMapping("ins/authorize")
    public String authorize(HttpServletResponse response){
        try {
            response.sendRedirect(actionService.insAuthorize());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return actionService.insAuthorize();
    }

    /**
     * URI 的末端会附加 #_，但它並不是代碼的一部分，因此請排除它
     */
    @GetMapping("ins/code")
    public void getCode(CodeVo codeVo){
        actionService.getCode(codeVo);
    }


}
